<template>
	<view class="content">
		<!-- 用户信息 -->
		<view class="user_section">
			<view class="user_set" @click="goTo('setCustomerInfo')">
				<u-icon color="#fff" name="setting" size="24px"></u-icon>
			</view>
			<!-- 背景 -->
			<image src="https://ipfs.s11edao.com/ipfs/QmVLZLVCKpWQXdH9ocPZCND9zry7sHyrpN1XkiYo2Fefhj" class="bg">
			</image>
			<!-- 信息 -->
			<view class="user_info_box">
				<!-- 登陆 -->
				<view class="login">
					<!-- 头像框 -->
					<view class="head_portrai_box" @click="goTo('mySpace')">
						<image :src="customerInfo.avatar || defaultAvatar"></image>
					</view>
					<view class="login_button" @click="goToLogin">
						{{ token ? customerInfo.username : '立即登录' }}
					</view>
				</view>
				<!-- 会员 -->
				<view class="vip">
					<view class="vip_info">
						<u-icon name="level" color="#CD7F32" size="30px"></u-icon>
						<view class="vip_level">钱包</view>
						<view class="open_vip" @click="getAnywebInfo" v-show="isAnyWebInfoShow">
							AnyWeb
						</view>
					</view>
					<!-- 会员权限 -->
					<view class="vip_equity">
						<text>VIP权益</text>
						<view class="open">
							请联系管理员开通
						</view>
					</view>
				</view>
			</view>
		</view>
		<!-- 功能部分 -->
		<view class="cover-container" :style="[{
				transform: coverTransform,
				transition: coverTransition
			}]" @touchstart="coverTouchstart" @touchmove="coverTouchmove" @touchend="coverTouchend">
			<image @click="goTo('wallet')" class="arc" src="../../static/images/my/arc.png"></image>
			<view class="option_section">
				<!-- 资产 -->
				<view class="assets_box" @click="goTo('wallet')">
					<view class="assets_box_item">
						<view class="assets_num">0</view>
						<text>火源</text>
					</view>
					<view class="assets_box_item">
						<view class="assets_num">{{yuanli}}</view>
						<text>原力</text>
					</view>
					<view class="assets_box_item">
						<view class="assets_num">0</view>
						<text>声誉</text>
					</view>
				</view>
				<!-- 功能 -->
				<!-- <view class="function_box">
					<view class="function_box_item" @click="goTo('pay')">
						<view>
							<image src="../../static/images/my/pay.png"></image>
						</view>
						<text>支付</text>
					</view>
					<view class="function_box_item" @click="goTo('transfer')">
						<view>
							<image src="../../static/images/my/transfer.png"></image>
						</view>
						<text>转账</text>
					</view>
					<view class="function_box_item" @click="goTo('recharge')">
						<view>
							<image src="../../static/images/my/recharge.png"></image>
						</view>
						<text>充值</text>
					</view>
				</view> -->
				<!-- 其他功能 -->
				<view class="set_box">
					<u-cell-group :border="false" customStyle="background:#fff">
						<u-cell isLink v-for="(item, index) in listCell" :key="index" size="large"
							@click="goTo(item.operationName)">
							<view slot="title" class="slot-title">
								<image class="icon_fun" :src="item.src"></image>
								<text class="u-cell-text">{{item.listName}}</text>
							</view>
						</u-cell>
					</u-cell-group>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getMyDigitalAssets,
	} from '@/config/customer.js'
	let startY = 0,
		moveY = 0,
		pageAtTop = true;
	export default {
		data() {
			return {
				defaultAvatar: 'https://ipfs.s11edao.com/ipfs/QmdQTcEnxVXbkSHaEH1AoJZ1AxMWEW5FbpdvGX2Yv7U5M3',
				// 是否展示获取anyWebInfo按钮
				isAnyWebInfoShow: true,
				coverTransform: 'translateY(0px)',
				coverTransition: '0s',
				moving: false,
				token: '',
				yuanli: '',
				customerInfo: {},
				// 设置列表
				listCell: [
					{
						listName: '我的任务',
						src: '../../static/images/my/task.png',
						operationName: 'myTask'
					},
					{
						listName: '社区Poap',
						src: '../../static/images/my/poap.png',
						operationName: 'poap'
					},
				],
			}
		},
		onTabItemTap(e) {
			// tab 点击时执行，此处直接接收单击事件
			console.log(e)
		},
		async onShow() {
			console.log('我的页面')
			this.token = uni.getStorageSync('token');
			this.customerInfo = uni.getStorageSync('customerInfo');

			// 钱包地址
			if (!this.util.isEmpty(uni.getStorageSync('ANYWEBINFO'))) {
				this.isAnyWebInfoShow = false
			} else {
				this.isAnyWebInfoShow = true
			}
			// 获取我的账户信息
			let res = await getMyDigitalAssets({
				customerNo: this.customerInfo.customerNo
			})
			this.yuanli = res.data.accountInfo[0].balance
		},
		methods: {
			/**
			 * 动画效果
			 */
			coverTouchstart(e) {
				if (pageAtTop === false) {
					return;
				}
				this.coverTransition = 'transform .1s linear';
				startY = e.touches[0].clientY;
			},
			coverTouchmove(e) {
				moveY = e.touches[0].clientY;
				let moveDistance = moveY - startY;
				if (moveDistance < 0) {
					this.moving = false;
					return;
				}
				this.moving = true;
				if (moveDistance >= 80 && moveDistance < 100) {
					moveDistance = 80;
				}

				if (moveDistance > 0 && moveDistance <= 80) {
					this.coverTransform = `translateY(${moveDistance}px)`;
				}
			},
			coverTouchend() {
				if (this.moving === false) {
					return;
				}
				this.moving = false;
				this.coverTransition = 'transform 0.3s cubic-bezier(.21,1.93,.53,.64)';
				this.coverTransform = 'translateY(0px)';
			},

			/**
			 * 登陆
			 * h5登陆
			 * anyweb登陆
			 */
			goToLogin() {
				if (this.token) {
					return
				}
				uni.navigateTo({
					url: "/pages/Login/Login"
				})
			},
			getAnywebInfo() {
				uni.navigateTo({
					url: "/pagesMy/AnyWeb"
				});
			},

			/**
			 * 跳转不同的链接 统一判断是否登陆	
			 */
			goTo(val) {
				if (!this.token && val != 'poap') {
					uni.$u.toast('请先登陆')
					return
				}
				switch (val) {
					// 我的主页
					case 'mySpace':
						uni.navigateTo({
							url: "/pagesMy/MySpace"
						})
						break;
						// 设置
					case 'setCustomerInfo':
						uni.navigateTo({
							url: "/pages/My/mySetting/MySet"
						})
						break;
						// 钱包
					case 'wallet':
						uni.navigateTo({
							url: "/pagesMy/Wallet"
						})
						break;
						// 支付
					case 'pay':
						uni.navigateTo({
							url: "/pagesMy/Pay"
						})
						break;
						// 转账
					case 'transfer':
						uni.navigateTo({
							url: "/pagesMy/Transfer"
						})
						break;
					case 'recharge':
						uni.navigateTo({
							url: "/pagesMy/Recharge"
						})
						break;
						// 任务
					case 'myTask':
						uni.navigateTo({
							url: "/pagesMy/MyTask"
						})
						break;
						// 提案
					case 'MyProposal':
						uni.navigateTo({
							url: "/pagesMy/MyProposal"
						})
						break;
						// 投票
					case 'MyVoting':
						uni.navigateTo({
							url: "/pagesMy/MyVoting"
						})
						break;
						// 社区poap
					case 'poap':
						uni.navigateTo({
							url: "/pagesMy/CommunityPoap"
						})
						break;
						// 订单
					case 'order':
						uni.navigateTo({
							url: "/pagesMy/MyOrder"
						})
						break;
						// 权益
					case 'myEquity':
						uni.navigateTo({
							url: "/pagesMy/MyEquity"
						})
						break;
					// 权益
					case 'myActivity':
						uni.navigateTo({
							url: "/pagesMy/MyActivity"
						})
						break;
					default:
						break;
				}
			}
		}
	}
</script>

<style scoped lang="scss">
	.content {
		position: absolute;
		width: 100%;
		height: 100%;
		background-color: #F9F9F9;
	}

	.user_section {
		height: 600rpx;
		position: relative;

		.user_set {
			position: absolute;
			top: 200rpx;
			right: 40rpx;
			z-index: 99;
		}

		.bg {
			width: 100%;
			height: 100%;
		}

		.user_info_box {
			position: absolute;
			top: 140rpx;
			width: 100%;

			.login {
				padding: 30rpx;
				display: flex;
				align-items: center;

				.head_portrai_box {
					width: 140rpx;
					height: 140rpx;
					border-radius: 50%;
					margin-right: 40rpx;
					border: 2px solid white;
					overflow: hidden;

					image {
						width: 100%;
						height: 100%;
					}
				}

				.login_button {
					color: white;
					font-size: $echo-font-size-title;
					font-weight: bold;
				}
			}

			.vip {
				margin: 0 30rpx;
				padding: 30rpx 30rpx;
				background-image: linear-gradient(to left, rgba(0, 0, 0, .7), rgba(0, 0, 0, .8));
				border-radius: 16rpx 16rpx 0 0;

				.vip_info {
					margin-bottom: 40rpx;
					display: flex;
					justify-content: space-between;
					align-items: center;

					.vip_level {
						flex: 1;
						color: #CD7F32;
						margin-left: 20rpx;
					}

					.open_vip {
						background-image: linear-gradient(to left, #f9e6af, #ffd465);
						text-align: center;
						border-radius: 20rpx;
						width: 150rpx;
						height: 40rpx;
						line-height: 40rpx;
					}

					.code {
						color: #fff;
					}
				}

				.vip_equity {

					text {
						color: #CD7F32;
					}

					.open {
						color: #777;
						margin-top: 16rpx;
						margin-bottom: 40rpx;
					}
				}
			}
		}
	}

	.cover-container {
		position: absolute;
		z-index: 2;
		top: 420rpx;
		width: 100%;

		.arc {
			width: 100%;
			height: 100rpx;
		}

		.option_section {
			background-color: #F9F9F9;
			position: relative;
			top: -20rpx;

			.assets_box {
				padding: 20rpx;
				margin: 0 30rpx;
				background-color: #FFFFFF;
				display: flex;
				justify-content: space-between;

				.assets_box_item {
					width: 30%;
					text-align: center;

					text {
						margin-top: 10rpx;
					}
				}
			}

			.function_box {
				display: flex;
				justify-content: space-between;
				padding: 40rpx 40rpx;
				margin: 30rpx;
				background-color: #FFFFFF;

				.function_box_item {
					width: 33.3%;
					text-align: center;

					image {
						width: 80rpx;
						height: 80rpx;
					}
				}
			}

			.set_box {
				margin: 30rpx;

				.slot-title {
					display: flex;

					.icon_fun {
						margin-right: 20rpx;
						width: 44rpx;
						height: 44rpx;
					}
				}

				::v-deep .slot-title {
					align-items: center;
				}
			}
		}
	}
</style>
